public class OddEvenList {
    // 链表的奇偶重排
    // https://www.nowcoder.com/practice/02bf49ea45cd486daa031614f9bd6fc3?tpId=295&tqId=1073463&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
    public ListNode oddEvenList (ListNode head) {
        // write code here
        ListNode pHead1 = new ListNode(-1);
        ListNode pHead2 = new ListNode(-1);
        ListNode cur1 = pHead1;
        ListNode cur2 = pHead2;
        ListNode cur = head;
        for (int i = 1; cur != null; i++) {
            if (i % 2 == 1) {
                cur1.next = cur;
                cur1 = cur1.next;
            } else {
                cur2.next = cur;
                cur2 = cur2.next;
            }
            cur = cur.next;
        }
        cur2.next = null;
        cur1.next = pHead2.next;
        return pHead1.next;
    }

    public static void main(String[] args) {
        OddEvenList oel = new OddEvenList();
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(4);
        head.next.next.next.next = new ListNode(5);
        System.out.println(oel.oddEvenList(head));

    }
}
